import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 64355
 * Date: 2022-08-01
 * Time: 1:41
 */
public class Test {
    public static int fa(int n){
        if(n==1){
            return 1;
        }
        return fa(n-1)*n;
    }
    public static void main(String[] args) {
        //递归求 N 的阶乘
        System.out.println("请输入一个整数");
        Scanner sc=new Scanner(System.in);
        int n =sc.nextInt();
        int ret =fa(n);
        System.out.println(ret);
    }
    public static int print(int n) {
        if (n < 10) {
//            System.out.print(n + " ");
            return n;
        }
//        n /= 10;

//        System.out.print(n % 10 + " ");
        return n%10+ print(n/10);
    }

    public static void main8(String[] args) {
//        Scanner scan =new Scanner(System.in);
//        int n= scan.nextInt();
        int n = 1234;
       int ret= print(n);
        System.out.println(ret);

    }

    public static int cmp(int x, int y) {
        if (x > y)
            return x;
        else
            return y;
    }

    public static double cmp(double x, double y, double z) {
        double max = x;
        if (y > max)
            max = y;
        if (z > max)
            max = z;
        return max;
    }

    public static void main7(String[] args) {
        //在同一个类中定义多个方法：要求不仅可以求2个整数的最大值，还可以求3个小数的最大值？
        System.out.println("请输入两个整数");
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        System.out.println("请输入三个小数");
        double x = scan.nextDouble();
        double y = scan.nextDouble();
        double z = scan.nextDouble();
        int ret = cmp(a, b);
        System.out.println("两个整数的最大值为" + ret);
        double ret2 = cmp(x, y, z);
        System.out.println("三个小数的最大值为" + ret2);
    }

    public static int sum(int x, int y) {
        return x + y;
    }

    public static double sum(double x, double y, double z) {
        return x + y + z;
    }

    public static void main3(String[] args) {
        //在同一个类中,分别定义求两个整数的方法 和 三个小数之和的方法。 并执行代码，求出结果
        System.out.println("请输入两个整数");
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        System.out.println("请输入三个小数");
        double x = scan.nextDouble();
        double y = scan.nextDouble();
        double z = scan.nextDouble();
        int ret = sum(a, b);
        double ret1 = sum(x, y, z);
        System.out.println(ret);
        System.out.println(ret1);
    }

    public static int fib(int x) {
        if (x == 1 || x == 2)
            return 1;
        else return fib(x - 1) + fib(x - 2);
    }

    public static void main6(String[] args) {
        //求斐波那契数列的第n项。(迭代实现)
        System.out.println("请输入一个值");
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int ret = fib(n);
        System.out.println(ret);
    }

    public static int fac(int n) {
        int sum = 1;
        for (int i = 1; i <= n; i++) {
            sum *= i;
        }
        return sum;
    }

    public static int fac1(int n) {
        int sum1 = 0;
        for (int i = 1; i <= n; i++) {
            sum1 += fac(i);
        }
        return sum1;
    }

    public static void main5(String[] args) {
        //求1！+2！+3！+4！+........+n!的和
        System.out.println("请输入一个整数n");
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int ret = fac1(n);
        System.out.println(ret);

    }

    public static void main4(String[] args) {
        //求 N 的阶乘 。
        System.out.println("请输入一个整数n");
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int ret = fac(n);
        System.out.println(ret);
    }

    public static int max3(int x, int y, int z) {
        int ret = max2(x, y);
        if (ret > z)
            return ret;
        else
            return z;
    }

    public static int max2(int x, int y) {
        if (x > y)
            return x;
        else
            return y;
    }

    public static void main2(String[] args) {
        //创建方法求两个数的最大值max2，随后再写一个求3个数的最大值的函数max3。
        // ​ 要求：在max3这个函数中，调用max2函数，来实现3个数的最大值计算
        System.out.println("请输入三个值");
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int ret = max2(a, b);
        int ret2 = max3(a, b, c);
        System.out.println("前两个数最大值为：" + ret);
        System.out.println("前三个数最大值为：" + ret2);
    }
}
